#include "ClkTimerInitHelper.h"

void INT_SRC_TMRA_1_UDF_IrqCallback(void)
{
    //add your codes here
	ms_cnt++;
	if (ms_cnt >= 1000) { ms_cnt = 0; }
}

void App_TimerACfg(void)
{
    stc_tmra_init_t stcTmraInit;

    FCG_Fcg0PeriphClockCmd(FCG0_PERIPH_AOS, ENABLE);
    /* TimerA trigger event 0 set */
    AOS_SetTriggerEventSrc(AOS_TMRA_0, EVT_SRC_TMRA_1_UDF);

    /* Enable TMRA_1 peripheral clock */
    FCG_Fcg2PeriphClockCmd(FCG2_PERIPH_TMRA_1, ENABLE);

    /************************* Configure TMRA_1 counter *************************/
    (void)TMRA_StructInit(&stcTmraInit);
    /* Config software count */
    stcTmraInit.sw_count.u8ClockDiv = TMRA_CLK_DIV8;
    stcTmraInit.sw_count.u8CountMode = TMRA_MD_SAWTOOTH;
    stcTmraInit.sw_count.u8CountDir = TMRA_DIR_DOWN;
    stcTmraInit.u32PeriodValue = 0x30D4U;
    (void)TMRA_Init(CM_TMRA_1, &stcTmraInit);

    /* Enable underflow interrupt */
    TMRA_IntCmd(CM_TMRA_1, TMRA_INT_UDF, ENABLE);

    /* Config hardware start */
    TMRA_HWStartCondCmd(CM_TMRA_1, TMRA_START_COND_EVT, ENABLE);

    /* Config hardware clear */
    TMRA_HWClearCondCmd(CM_TMRA_1, TMRA_CLR_COND_EVT, ENABLE);

    /* Start timerA */
    TMRA_Start(CM_TMRA_1);
}
